package Controller.DepServlet;

import Dao.DepDao;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/dep_batchDelete")
public class dep_batchDelete extends HttpServlet {
    DepDao depDao = new DepDao();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String dno_list_str = req.getParameter("dno_list");
        String[] dno_list = dno_list_str.split(",");
        System.out.println(Arrays.toString(dno_list));
        depDao.batchDelete(dno_list);
        Map<String, Object> map = new HashMap<>();
        map.put("msg", "删除成功");
        map.put("code", 200);
        resp.getWriter().write(JSON.toJSONString(map));
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
